package vd

import (
	"testing"
	"bytes"
	"strings"
	"compress/gzip"
)


var sampleText = `VerboseData01
[] | :vd:Shape:
	| :vd:Shape:
		{} :vd:Point:
			name string
				"O"
			coordinate {} :vd:Vector:
				x float
					0
				y float
					0
	| :vd:Shape:
		{} :vd:PointGroup:
			points [] {} :vd:Point:
				{} :vd:Point:
					name string
						"A"
					coordinate {} :vd:Vector:
						x float
							1
						y float
							1
				{} :vd:Point:
					name string
						"B"
					coordinate {} :vd:Vector:
						x float
							-5
						y float
							7
				{} :vd:Point:
					name string
						"C"
					coordinate {} :vd:Vector:
						x float
							10
						y float
							15
	| :vd:Shape:
		{} :vd:Circle:
			center {} :vd:Vector:
				x float
					4.2
				y float
					7.4
			radius float
				10
	| :vd:Shape:
		{} :vd:Empty:
`
func testDeserializeBigGzipped(n uint) (Object, *Type, error) {
	var ts, _ = CreateGoStructTransformer(sampleOptions)
	var bin, _, err1 = testSerializeBigGzipped(n)
	if err1 != nil { return nil, nil, err1 }
	var reader, err2 = gzip.NewReader(bytes.NewReader(bin))
	if err2 != nil { return nil, nil, err2 }
	return Deserialize(reader, ts.Deserializer)
}

func TestDeserialize(t *testing.T) {
	t.Log("deserialize a sample text")
	var ts, _ = CreateGoStructTransformer(sampleOptions)
	var reader = strings.NewReader(sampleText)
	var obj, typ, err = Deserialize(reader, ts.Deserializer)
	if err != nil { t.Fatal(err) }
	t.Logf("%s\n%+v", typ, obj)
}

func TestDeserializeBigGzipped1e3(t *testing.T) {
	var _, _, err = testDeserializeBigGzipped(1000)
	if err != nil { t.Fatal(err) }
}

func TestDeserializeBigGzipped1e4(t *testing.T) {
	var _, _, err = testDeserializeBigGzipped(10000)
	if err != nil { t.Fatal(err) }
}

func TestDeserializeBigGzipped1e5(t *testing.T) {
	var _, _, err = testDeserializeBigGzipped(100000)
	if err != nil { t.Fatal(err) }
}


